package com.xyzwps.harbor.util;

import org.springframework.http.HttpStatus;

import java.util.Objects;

public class HarborException extends RuntimeException {

    public final HttpStatus status;
    public final ErrorCode code;

    public HarborException(String message, HttpStatus status, ErrorCode code) {
        super(message);
        this.status = Objects.requireNonNull(status);
        this.code = Objects.requireNonNull(code);
    }

    public static HarborException badRequestEx(String message, ErrorCode code) {
        return new HarborException(message, HttpStatus.BAD_REQUEST, code);
    }

    public static HarborException badRequestEx(String message) {
        return new HarborException(message, HttpStatus.BAD_REQUEST, ErrorCode.BAD_REQUEST);
    }

    public static HarborException notImplEx(String message) {
        return new HarborException(message, HttpStatus.NOT_IMPLEMENTED, ErrorCode.NOT_IMPL);
    }

    public static HarborException incorrectCode(String message) {
        return new HarborException(message, HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.INCORRECT_CODE);
    }

}